# Makefile for Dackel

CXX=g++
CXXFLAGS=-Wall

CC=gcc
CFLAGS=-Wall

# this must be adjusted to your installation
# e.g. INCLUDE=/home/perkeo/alex/sis1100/V1.0/sis3100_calls,
# for version 1.0 of the sis driver
LIBDIR=-L../sis1100/sis3100_calls
LIBS=-l_sis3100 -lz
INCLUDE=-I../sis1100/sis3100_calls\
        -I../sis1100/dev/pci

SRCS =	VmeModule.cpp Counter_DL636G1.cpp DigitalIO_DL636F.cpp\
	IOError.cpp ADC_DL642A.cpp TimeCounter_DL643A1.cpp\
	Latch_SIS3600.cpp teebuf.cpp\
	TDC_V767.cpp ConfigReader.cpp\
	FIFO32DMAReader.cpp BufferedVMEReader.cpp\
	StartStop.cpp DklHeader.cpp\
	QDC_V792.cpp vme_sis.cpp stringutil.cpp

#TestFIFO32DMAReader.cpp 
CSRCS=	sis3100_dma.c

OBJS=$(SRCS:.cpp=.o) $(CSRCS:.c=.o)
HDRS=$(SRCS:.cpp=.h) $(CSRCS:.c=.h)

# see "Managing Projects with GNU Make", Ch.2, P.16/17
# for explanation of $< and stuff
# (http://www.oreilly.com/catalog/make3/book/ch02.pdf)
%.o: %.cpp %.h
%.o: %.cpp %.h config.h
	$(CXX) $(CXXFLAGS) $(INCLUDE) -c $< -o $@
%.o: %.c %.h
	$(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@

TARGETS = dackel sendpulse dkl2root spektrum bin hist 

all: $(TARGETS)


dackel: main.cpp $(OBJS) $(HDRS)
	$(CXX) $(CXXFLAGS) $(LIBDIR) $(INCLUDE) -o dackel $(OBJS) main.cpp $(LIBS) 

dackel2: dackel2.cpp $(OBJS) $(HDRS)
	$(CXX) $(CXXFLAGS) $(LIBDIR) $(INCLUDE) -o dackel2 $(OBJS) dackel2.cpp $(LIBS) 

sendpulse: sendpulse.cpp $(OBJS) $(HDRS)
	$(CXX) $(CXXFLAGS) $(LIBDIR) $(INCLUDE) -o sendpulse $(OBJS) sendpulse.cpp $(LIBS) 

dkl2root: dkl2root.cpp DklHeader.o EventStruct.h EventStructVer1.h config.h
	$(CC) -o dkl2root $(CFLAGS) $(INCLUDE) dkl2root.cpp DklHeader.o -lz $(shell root-config --libs --cflags)


bin: bin.cpp
	$(CXX) $(CXXFLAGS) -o bin bin.cpp	

spektrum: spektrum.cpp $(OBJS) $(HDRS)
	$(CXX) $(CXXFLAGS) $(LIBDIR) $(INCLUDE) -o spektrum $(OBJS) spektrum.cpp $(LIBS) 

hist:	hist.cpp
	$(CXX) $(CXXFLAGS) -o hist hist.cpp


dkltool: dkltool.cpp EventStruct.h DklHeader.o
	$(CXX) $(CXXFLAGS) -o dkltool dkltool.cpp DklHeader.o -lz

dkl2dat: dkl2dat.c EventStruct.h
	$(CC) $(CFLAGS) -o dkl2dat dkl2dat.c -lz


testseq: testseq.cpp $(OBJS) $(HDRS)
	$(CXX) $(CXXFLAGS) $(LIBDIR) $(INCLUDE) -o testseq $(OBJS) testseq.cpp $(LIBS) 

test_TimeCounter: test_TimeCounter.cpp $(OBJS) $(HDRS)
	$(CXX) $(CXXFLAGS) $(LIBDIR) $(INCLUDE) -o test_TimeCounter $(OBJS) test_TimeCounter.cpp $(LIBS) 

test_TDC: test_TDC.cpp $(OBJS) $(HDRS)
	$(CXX) $(CXXFLAGS) $(LIBDIR) $(INCLUDE) -o test_TDC $(OBJS) test_TDC.cpp $(LIBS) 

test_QDC_V792: test_QDC_V792.cpp $(OBJS) $(HDRS)
	$(CXX) $(CXXFLAGS) $(LIBDIR) $(INCLUDE) -o test_QDC_V792 $(OBJS) test_QDC_V792.cpp $(LIBS) 

test_ConfigReader: test_ConfigReader.cpp $(OBJS) $(HDRS)
	$(CXX) $(CXXFLAGS) $(LIBDIR) $(INCLUDE) -o test_ConfigReader $(OBJS) test_ConfigReader.cpp $(LIBS) 

test_BufferVMEReader: test_BufferedVMEReader.cpp $(OBJS) $(HDRS)
	$(CXX) $(CXXFLAGS) $(LIBDIR) $(INCLUDE) -o test_BufferedVMEReader $(OBJS) test_BufferedVMEReader.cpp $(LIBS) 

test_teebuf: test_teebuf.cpp teebuf.h
	$(CXX) $(CXXFLAGS) -o test_teebuf test_teebuf.cpp

gztest: gztest.c
	$(CC) $(CCFLAGS) $(LIBDIR) $(INCLUDE) gztest.c -lz -o gztest

exp_test: exp_test.c
	$(CC) $(CCFLAGS) $(LIBDIR) $(INCLUDE) exp_test.c -o exp_test

test_DigitalIO: test_DigitalIO.cpp DigitalIO_DL636F.h DigitalIO_DL636F.cpp
	$(CXX) $(CXXFLAGS) $(LIBDIR) $(INCLUDE) test_DigitalIO.cpp -o test_DigitalIO $(OBJS) $(LIBS)

test_StartStop: test_StartStop.cpp StartStop.h StartStop.cpp
	$(CXX) $(CXXFLAGS) $(LIBDIR) $(INCLUDE) test_StartStop.cpp -o test_StartStop $(OBJS) $(LIBS)

test_rate: test_rate.cpp $(OBJS) $(HDRS)
	$(CXX) $(CXXFLAGS) $(LIBDIR) $(INCLUDE) test_rate.cpp -o test_rate $(OBJS) $(LIBS)


clean:
	rm *.o
	rm $(TARGETS)

install: install-dkl2root

install-dkl2root: dkl2root
	chown perkeo:users dkl2root
	chmod g-w,o-w dkl2root
	cp dkl2root /usr/local/bin
	
install-dackel:
	chown knecht:users dackel
	chmod u+s,g+s,g-w,o-w dackel
	cp dackel /usr/local/bin
#	cp dackel.cfg /etc
